package com.myblog.controller;

import com.myblog.annotation.Log;
import com.myblog.domain.GlobalResponse;
import com.myblog.domain.entity.User;
import com.myblog.domain.entity.enums.GlobalResponseEnum;
import com.myblog.expection.GlobalException;
import com.myblog.services.LoginService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

@RestController
@Api(tags = "登录控制器")
public class LogInController {
    @Resource
    LoginService loginService;
    @PostMapping("/login")
    @Log(BusinessName = "前台登录")
    @ApiOperation(value = "前台登录")
    public GlobalResponse LogIn(@RequestBody User user){
        if(!StringUtils.hasText(user.getUserName())){
            throw new GlobalException(GlobalResponseEnum.REQUIRE_USERNAME);
        }
        return loginService.Login(user);
    }
}
